package com.quarters.controller;

import com.quarters.service.XbxWxService;
import me.chanjar.weixin.mp.api.WxMpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author 张子艺
 * @packge com.xbxkj.controller
 * @data 2019-06-04 17:42
 * @project Metaphysics
 */
@Controller
@RequestMapping("/")
public class WebsocketController {


    @Autowired
   XbxWxService xbxWxService;

    @RequestMapping(value = "/checkToken" )
    public void checkToken(String signature, String timestamp, String nonce, String echostr, HttpServletRequest request, HttpServletResponse response) throws Exception {
    WxMpService wxMpService= xbxWxService.getWxService();
    if(wxMpService.checkSignature(timestamp,nonce,signature)) {
        try {
            response.getWriter().print(echostr);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    }


}
